home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / btr_oop.exe / BTRV_IO.PAS < prev    next >
Pascal/Delphi Source File  |  1991-06-03  |  16KB  |  336 lines

  1. UNIT BTRV_IO;
  2.  
  3. INTERFACE
  4.  
  5. USES DOS,GLOBALS,BTRV,OBJECTS;
  6.  
  7. Var
  8.   {global variables}
  9.   Status : Integer;
  10.  
  11. { ---------------------Usable User Interface--------------------------------}
  12.   { This is the first decendent of the TBtrieve object with an attempt to make }
  13.   { the calls to the Btrv blackbox more user friendly. This attempt fails  }
  14.   { badly for certain calls especially the extended ones. Anyway the idea  }
  15.   { is to use decendents of this object with record structures added so    }
  16.   { you end up with database files/database views that know how to work on }
  17.   { themselves.}
  18.  
  19. Type
  20.   { This is the varient record for the Key Buffer part of the Btrv call. }
  21.   KeyBuffRecord = Record
  22.   Case Integer of
  23.     1: (IndxString : String);
  24.     2: (length     : byte;
  25.         StrAry     : Array[1..255] of Char);
  26.   end;
  27.  
  28. Type
  29.   PBT_IO = ^TBT_IO;
  30.   TBT_IO = object(TBtrieve)
  31.     btDataRec    : Pointer;
  32.     btDataRecLen : Integer;
  33.     btKeyBuff    : KeyBuffRecord;
  34.     btKey        : Integer;
  35.     Constructor Init;
  36.     Destructor Done; Virtual;
  37.  
  38.     Procedure SetKeyIndx(KeyNum: Integer);    { use to set the index path }
  39.  
  40.     Function OpenFile (FileName: TypStr25; OpenMode: Integer): Integer;  {0}
  41.     Function CloseFile : Integer;                                        {1}
  42.     Function InsertRecord : Integer;                                     {2}
  43.     Function UpdateRecord : Integer;                                     {3}
  44.     Function DeleteRecord: Integer;                                      {4}
  45.     Function GetEq(ValueStr: String): Integer;                           {5}
  46.     Function GetNext : Integer;                                          {6}
  47.     Function GetPrevious : Integer;                                      {7}
  48.     Function GetGr(ValueStr: String): Integer;                           {8}
  49.     Function GetGrOrEq(ValueStr: String) : Integer;                      {9}
  50.     Function GetLs(ValueStr: String) : Integer;                         {10}
  51.     Function GetLsOrEq(ValueStr: String): Integer;                      {11}
  52.     Function GetFirst : Integer;                                        {12}
  53.     Function GetLast : Integer;                                         {13}
  54.     Function BeginTran: Integer;                                        {19}
  55.     Function EndTran: Integer;                                          {20}
  56.     Function AbortTran: Integer;                                        {21}
  57.     Function GetPosition(Var Pozition: LongInt): Integer;               {22}
  58.     Function GetDirect(Pozition: LongInt): Integer;                     {23}
  59.     Function StepNext  : Integer;                                       {24}
  60.     Function StopBt: Integer;                                           {25}
  61.     Function StepFirst : Integer;                                       {33}
  62.     Function StepLast  : Integer;                                       {34}
  63.     Function StepPrevious : Integer;                                    {35}
  64.   end;
  65.  
  66. IMPLEMENTATION
  67.  
  68. {---------------------- TBT_IO Ancestor Object -------------------------------}
  69. Constructor TBT_IO.Init;
  70. begin
  71.   TBtrieve.Init;
  72. end;
  73.  
  74. Destructor TBT_IO.Done;
  75. begin
  76.   TBtrieve.Done;
  77. end;
  78.  
  79. {-------------------------- Set Key Index -----------------------------------}
  80. Procedure TBT_IO.SetKeyIndx(KeyNum: Integer);    { use to set the index path }
  81. begin
  82.   btKey := KeyNum;
  83. end; {----------------- Set Key Index ---------------------------------------}
  84. {-------------------- Btrieve Open (0) --------------------------------------}
  85. Function TBT_IO.OpenFile(FileName: TypStr25; OpenMode: Integer): Integer;  {0}
  86. { Opens a Btrieve file and returns the status code. Note this assumes no }
  87. { owner of the file. }
  88. var
  89.    OwnerLen : integer;
  90.    Owner    : string[10];
  91. begin
  92.   btKeyBuff.IndxString := FileName + #0;
  93.   Owner := #0;
  94.   OwnerLen := 0;
  95.   OpenFile := Btrv(0,                                   { 0 = Btrieve Open }
  96.                  Owner[1],
  97.                  OwnerLen,
  98.                  btKeyBuff.StrAry,
  99.                  OpenMode);
  100. end; { ------------------- Btrieve Open -------------------------------------}
  101. Function TBT_IO.CloseFile : Integer;                                       {1}
  102. Begin
  103.   CloseFile := Btrv(1,                                  { 1 = Btrieve Close }
  104.                     btDataRec^,
  105.                     btDataRecLen,
  106.                     btKeyBuff.IndxString[1],
  107.                     0);
  108. End;{ ----------------------Btrieve Close -----------------------------------}
  109. {------------------------- Btrieve Insert (2) -------------------------------}
  110. Function TBT_IO.InsertRecord : Integer;                                    {2}
  111. begin
  112.   InsertRecord := Btrv(2,                               { 2 = Btrieve Insert }
  113.                        btDataRec^,
  114.                        btDataRecLen,
  115.                        btKeyBuff,
  116.                        btKey);
  117. end; {-------------------- Btrieve Insert -----------------------------------}
  118. {------------------------- Btrieve Update (3) -------------------------------}
  119. Function TBT_IO.UpdateRecord : Integer;                                    {3}
  120. begin
  121.   UpdateRecord := Btrv(3,                               { 3 = Btrieve Update }
  122.                        btDataRec^,
  123.                        btDataRecLen,
  124.                        btKeyBuff,
  125.                        btKey);
  126. end; {-------------------- Btrieve Update -----------------------------------}
  127. {------------------------- Btrieve Delete (4) -------------------------------}
  128. Function TBT_IO.DeleteRecord:Integer;                                      {4}
  129. { Note that the Key number is not passed in as a parameter. This is bacause  }
  130. { if you are following Btrieves rules correctly the delete came right after  }
  131. { a get so the btKey would already bee correctly set.                        }
  132.  
  133. begin
  134.   DeleteRecord := Btrv(4,                               { 4 = Btrieve Delete }
  135.                        btDataRec^,
  136.                        btDataRecLen,
  137.                        btKeyBuff,
  138.                        btKey);
  139. end; {-------------------- Btrieve Delete -----------------------------------}
  140. {----------------------- Btrieve Get Equal (5) ------------------------------}
  141. Function TBT_IO.GetEq(ValueStr: String): Integer;                          {5}
  142. begin
  143.   btKeyBuff.IndxString := ValueStr + Spaces;
  144.   GetEq := Btrv(5,                                   { 5 = Btrieve Get Equal }
  145.                 btDataRec^,
  146.                 btDataRecLen,
  147.                 btKeyBuff.IndxString,
  148.                 btKey);
  149. end; {----------------- Btrieve Get Equal -----------------------------------}
  150. {----------------------- Btrieve Get Next (6) -------------------------------}
  151. Function TBT_IO.GetNext : Integer;                                         {6}
  152. { Notice that get next has no KeyNum parameter. The assumption is that some  }
  153. { key path has already been set.}
  154. begin
  155.   GetNext := Btrv(6,                                  { 6 = Btrieve Get Next }
  156.                   btDataRec^,
  157.                   btDataRecLen,
  158.                   btKeyBuff,
  159.                   btKey);
  160. end; {----------------- Btrieve Get Next ------------------------------------}
  161. {--------------------- Btrieve Get Previous (7) -----------------------------}
  162. Function TBT_IO.GetPrevious : Integer;                                     {7}
  163. { Notice that this has no KeyNum parameter. The assumption is that some key  }
  164. { path has already been set.}
  165. begin
  166.   GetPrevious := Btrv(7,                          { 7 = Btrieve Get Previous }
  167.                       btDataRec^,
  168.                       btDataRecLen,
  169.                       btKeyBuff,
  170.                       btKey);
  171. end; {----------------- Btrieve Get Previous --------------------------------}
  172. {----------------------- Btrieve Get Greater (8) ----------------------------}
  173. Function TBT_IO.GetGr(ValueStr: String): Integer;                          {8}
  174. begin
  175.   btKeyBuff.IndxString := ValueStr + Spaces;
  176.   GetGr := Btrv(8,                                 { 8 = Btrieve Get Greater }
  177.                 btDataRec^,